<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://unpkg.com/vue@3.4.27/dist/vue.global.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/@picocss/pico@2.0.6/css/pico.css">
    <script src="https://unpkg.com/axios@1.7.2/dist/axios.min.js"></script>
    <title>会员积分商城 - 登录</title>
    <style>
        .container {
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            background-color: rgba(255, 255, 255, 0); /* 容器背景透明 */
            border-radius: 8px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }
        form {
            background-color: transparent; /* 表单背景透明 */
            padding: 20px;
            border-radius: 8px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #000; /* 标签文字颜色改为黑色 */
        }
        .btn {
            width: 100%;
            padding: 12px;
            font-size: 16px;
        }
        .btn-secondary {
            background-color: #6c757d;
            color: #fff;
            border: none;
            margin-top: 10px;
        }
        input.form-control {
            background-color: rgba(255, 255, 255, 0.9); /* 输入框背景半透明 */
            border: 1px solid #ccc;
            border-radius: 4px;
            padding: 10px;
            width: 100%;
            color: #000; /* 输入文字颜色改为黑色 */
        }
        html, body {
            height: 100%;
            margin: 0;
        }
        body {
            background-image: url('img_13.png');
            background-size: cover;
            background-position: center;
            min-height: 100vh;
            background-attachment: fixed;
        }
        h1.text-center {
            color: #000; /* 标题文字颜色改为黑色 */
        }
        p {
            color: #fff; /* 文字颜色保持不变 */
        }
    </style>
</head>
<body>
<div id="app" class="container-fluid py-5">
    <div class="container">
        <h1 class="text-center mb-4">会员积分商城</h1>
        <div class="row justify-content-center">
            <div class="col-md-6">
                <form @submit.prevent="login" class="bg-white rounded p-3 shadow-sm">
                    <div class="form-group">
                        <label for="username" class="font-weight-bold">用户名</label>
                        <input type="text" v-model="username" id="username" class="form-control" required />
                    </div>
                    <div class="form-group">
                        <label for="password" class="font-weight-bold">密码</label>
                        <input type="password" v-model="password" id="password" class="form-control" required />
                    </div>
                    <button type="submit" class="btn btn-primary btn-block">登录</button>
                </form>
                <p>还没有账号？ <button class="btn btn-secondary" @click="goToRegister">去注册</button></p>
            </div>
        </div>
    </div>
</div>
<script>
    const App = {
        data() {
            return {
                username: '',
                password: ''
            };
        },
        methods: {
            login() {
                axios.post('/api/users/login', {
                    username: this.username,
                    password: this.password,
                })
                    .then(response => {
                        const userId = response.data.id;
                        window.location.href = `index.html?userId=${userId}`;
                    })
                    .catch(error => {
                        console.error("登录失败：", error);
                        alert("用户名或密码错误，请重试！");
                    });
            },
            goToRegister() {
                window.location.href = 'register.html';
            }
        }
    };
    const app = Vue.createApp(App);
    app.mount("#app");
</script>
</body>
</html>